package com.bourne.annotation.aspect;

import com.bourne.annotation.CountTime;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @author bourne
 * @Description: 方法耗时逻辑
 * @date 2022/1/25 21:23
 */
@Aspect
@Component
@Slf4j
public class CountTimeAspect {

    @Around("@annotation(countTime)")
    public Object running (ProceedingJoinPoint pjp, CountTime countTime) throws Throwable {
        long beginTime = System.currentTimeMillis();
        Object obj = pjp.proceed();
        String methodName = pjp.getSignature().getName();
        String className = pjp.getSignature().getDeclaringTypeName();
        long endTime = System.currentTimeMillis();
        log.info(className + "中->" + methodName + "方法共计耗时：{}", (endTime - beginTime) + " ms");
        return obj;
    }

    public static void main(String[] args) {

// dadfasdf          dafdsaf

    }
}
